﻿document.onkeydown = function (e) {
    var e = window.event || e;
    var element = e.srcElement || e.target;
    if (e.keyCode == 13
        && element.type != "submit"
        && element.type != "button"
        && element.type != "textarea" 
        && element.type != "reset") {
        if (document.all) {
            e.keyCode = 9;
        } else {
            getNextInput(element).focus();
            e.preventDefault();
        }
    }
}
function getNextInput(input) {
    var form = input.form;
    for (var i = 0; i < form.elements.length; i++) {
        if (form.elements[i] == input) {
            break;
        }
    }
    while (true) {
        if (i++ < form.elements.length) {
            if (form.elements[i].type == "text") {
                return form.elements[i];
            }
        } else {
            return null;
        }
    }
}